﻿//https://leetcode.cn/problems/permutations/?envType=study-plan-v2&envId=top-100-liked

class Solution {
    bool vist[7];
    int n;
    vector<vector<int>> ret;
    vector<int> path;
public:
    vector<vector<int>> permute(vector<int>& nums)
    {
        n = nums.size();
        dfs(nums);
        return ret;
    }

    void dfs(vector<int>& nums)
    {
        if (path.size() == nums.size())
        {
            ret.push_back(path);
            return;
        }

        for (int i = 0; i < n; i++)
        {
            if (!vist[i])
            {
                path.push_back(nums[i]);
                vist[i] = true;
                dfs(nums);
                path.pop_back(); //恢复现场
                vist[i] = false;
            }
        }
    }
};